<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.dcm.mysearcher.dao.po.InforBeanCollection"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<jsp:include page="include.jsp" />
<head>

<base href="<%=basePath%>">

<title>${values}- Mustard</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

<style type="text/css">
.content {
	line-height: 115%;
	font-size: 100%;
	width: 33.7em;
	word-break: break-all;
	word-wrap: break-word;
	margin: 0px 0px 0px 50px;
}
</style>
</head>

<body>
	<%--
		java代码写在jsp中是不合理的,有待改进
	--%>
	<%
		InforBeanCollection ibc = (InforBeanCollection) request
				.getAttribute("ibc");

		if (ibc == null) {
			return;
		}

		int pageSize = (Integer) (session.getAttribute("pageSize"));
		int tmp = ibc.getIbs().size() % pageSize;
		int totalPage = 0;
		if (tmp == 0) {
			totalPage = ibc.getIbs().size() / pageSize;
		} else {
			totalPage = ibc.getIbs().size() / pageSize + 1;
		}
		String pagi = request.getParameter("pagination");
		int pagination = 1;
		if (pagi != null) {
			pagination = Integer.parseInt(pagi);
			//out.println(pagination);
		}
		if (pagination > totalPage) {
			pagination = totalPage;
		}
		if (pagination < 1) {
			pagination = 1;
		}
		int start = pageSize * (pagination - 1);
		int end = start + pageSize;
		end = end < ibc.getIbs().size() ? end : ibc.getIbs().size();

		for (int i = start; i < end; i++) {
	%>
	<br>
	<div class="content">
		<%
			String title = "<a href=" + ibc.getIbs().get(i).getUrl() + ">"
						+ ibc.getIbs().get(i).getTitle() + "</a><br>";
				out.println(title);
				String body = ibc.getIbs().get(i).getContent() + "......";
				out.println(body);
		%>
	</div>
	<%
		}
	%>

	<br>
	<br>
	<div align="center">
		<a href="searcher.jsp?values=${values}&pagination=1">首页</a> 
		<a href="searcher.jsp?values=${values}&pagination=<%=pagination -1 %>">上一页</a>
		<a href="searcher.jsp?values=${values}&pagination=<%=pagination +1 %>">下一页</a>
		<a href="searcher.jsp?values=${values}&pagination=<%=totalPage %>">末页</a>


	</div>
</body>
</html>
